home *** CD-ROM | disk | FTP | other *** search
- // I N C L U D E /////////////////////////////////////////////////////////////
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <string.h>
- #include <wgt5.h>
-
- #include "rle_spr.h"
-
- // D E F I N E S ///////////////////////////////////////////////////////////
-
- #define WGTFILEFORMAT 1
- #define RLEFILEFORMAT 2
-
- // G L O B A L S ////////////////////////////////////////////////////////////
-
- char copyright[]="Sprite File Converter Copyright 1997 Aleksei Sujurov";
-
- color pal[256];
- block sprites[2001];
-
- char* infile;
- char* outfile;
-
- char string[256];
-
- char sstr[18];
- short sver;
-
- // P R O T O T Y P E S //////////////////////////////////////////////////////
-
- void FatalError(char* Error, char* Routine, short Line);
- int FileExist (char* filename);
- char DetectSprFormat (void);
- void Timer_Ctr (void);
- void WGT_To_RLE (void);
- void RLE_To_WGT (void);
-
- // F U N C T I O N S /////////////////////////////////////////////////////////
-
- void main (int argc, char *argv[])
- {
- short ver;
- short ch;
-
- fprintf (stderr, "\nWGT sprite file to/from RLE sprite file converter 1.0\n");
- fprintf (stderr, "Copyright 1997 Aleksei Sujurov\n\n");
-
- if( argc <= 2 )
- {
- fprintf (stderr, "Syntax: SPRCONV infile outfile\n");
- fprintf (stderr, "\tinfile\t\tWGT or RLE sprite file, which should be converted\n");
- fprintf (stderr, "\toutfile\t\tName of a target file\n");
- exit (-1);
- }
-
- if ((strlen (argv[1]) >12) || (strlen (argv[2]) >12))
- {
- sprintf (string, "Name of a file too long !!!");
- FatalError (string, "main", __LINE__);
- }
-
- infile=strdup (argv[1]);
- outfile=strdup (argv[2]);
-
-
- if (!FileExist (infile))
- {
- sprintf (string, "File \"%s\" not exist !\n", infile);
- FatalError (string, "main", __LINE__);
- }
-
- if (FileExist (outfile))
- {
- fprintf (stderr, "File \"%s\" exist! Overwrite? (Y/N) >", outfile);
- ch=getch ();
-
- if (ch!='Y' && ch!='y')
- {
- puts ("NO");
- exit (-1);
- }
- else
- puts ("YES");
-
- }
-
- ver=DetectSprFormat ();
-
- switch (ver)
- {
- case WGTFILEFORMAT:
- WGT_To_RLE ();
- break;
-
- case RLEFILEFORMAT:
- RLE_To_WGT();
- break;
-
- default:
- sprintf (string, "\"%s\" is not sprite file ", infile);
- FatalError (string, "main", __LINE__);
- }
-
- wstoptimer();
- wdonetimer();
-
- }
-
- //////////////////////////////////////////////////////////////////////////////
-
- char DetectSprFormat (void)
- {
- FILE* fp;
- short i;
-
- fp=fopen (infile, "rb");
-
- fread (&sver, 2, 1, fp);
- fread (sstr, 17, 1, fp);
-
- fclose (fp);
-
- if ((i=strnicmp (sstr, " RLE Sprite File ", 17)==0 && sver == 1))
- return RLEFILEFORMAT;
- else
- if ((i=strnicmp (sstr, " Sprite File ", 13)==0 && sver == 4))
- return WGTFILEFORMAT;
-
- return 0;
-
- }
-
- //////////////////////////////////////////////////////////////////////////////
-
- void WGT_To_RLE (void)
- {
-
- fprintf (stderr, "\nConverting \"%s\" to \"%s\" :\n", infile, outfile);
- winittimer();
- wstarttimer(Timer_Ctr, TICKS(60));
-
- if (wloadsprites (pal, infile, sprites, 0, 2000)!=0)
- {
- sprintf (string, "Can't load Sprite file. (Probably shortage of memory)");
- FatalError (string, "WGT_To_RLE", __LINE__);
- }
-
- if (wsavesprites_rle (pal, outfile, sprites, 0, 2000)!=0)
- {
- remove (outfile);
- sprintf (string, "Can't save Sprite file. (Probably disk full)");
- FatalError (string, "WGT_To_RLE", __LINE__);
- }
-
- }
-
- //////////////////////////////////////////////////////////////////////////////
-
- void RLE_To_WGT (void)
- {
-
- fprintf (stderr, "\nConverting \"%s\" to \"%s\" :\n", infile, outfile);
- winittimer();
- wstarttimer(Timer_Ctr, TICKS(60));
-
- if (wloadsprites_rle (pal, infile, sprites, 0, 2000)!=0)
- {
- sprintf (string, "Can't load Sprite file. (Probably shortage of memory)");
- FatalError (string, "RLE_To_WGT", __LINE__);
- }
- if (wsavesprites (pal, outfile, sprites, 0, 2000)!=0)
- {
- remove (outfile);
- sprintf (string, "Can't save Sprite file. (Probably disk full)");
- FatalError (string, "RLE_To_WGT", __LINE__);
- }
-
- }
-
- //////////////////////////////////////////////////////////////////////////////
-
- int FileExist (char* filename)
- {
-
- FILE* fp;
-
- fp=fopen (filename, "r");
- fclose (fp);
-
- return fp==NULL ? 0 : 1;
-
- }
-
- void FatalError(char* Error, char* Routine, short Line)
- {
-
- wstoptimer();
- wdonetimer();
- fprintf(stderr, "\nERROR in %s, line %d! :\n%s", Routine, Line, Error);
- exit(-1);
- }
-
- void Timer_Ctr (void)
- {
-
- cputs (".");
-
- }